package com.homegoods.home.utils;

import com.homegoods.home.model.SearchListModel;

import org.litepal.LitePal;

import java.util.List;

/**
 * @author lenovo
 * @date 2017/6/1
 * 历史记录数据库工具
 */
public class SearchHistoryUtil {

    /**
     * 新增历史记录
     *
     * @param searchListModel
     */
    public static void saveSearchList(SearchListModel searchListModel) {
        List<SearchListModel> searchList = getSearchList();
        for (SearchListModel searchModel : searchList) {
            if (searchModel.getTitle().equals(searchListModel.getTitle())) {
                return;
            }
        }

        searchListModel.save();
    }

    /**
     * 获取搜索历史列表，保存本地数据库的数据
     *
     * @return
     */
    public static List<SearchListModel> getSearchList() {
        return LitePal.findAll(SearchListModel.class);
    }

    /**
     * 清除历史记录
     */
    public static void clearSearchList() {
        LitePal.deleteAll(SearchListModel.class);
    }

}
